import { defineStore } from 'pinia';
import { ref } from 'vue';
import type { Ref } from 'vue';
import useTabsStore from '@/store/modules/tabs'




const useRouterStore = defineStore('router', () => {
    const tabsStore = useTabsStore()
    const currentRoutePath: Ref<string> = ref('/home')
    const currentRouteInfo: Ref<string[]> = ref([])
    function changeRoutePath(to) {


        currentRouteInfo.value = []
        currentRoutePath.value = to.path;


        if (to.matched.filter(i => i.name === '首页').length) {
            currentRouteInfo.value.push('首页')
        } else {
            (to.matched || []).forEach((item) => {

                currentRouteInfo.value.push(item.name)


            })
        }



        tabsStore.setTabActive(to.path)
        document.title = import.meta.env.VITE_APP_TITLE + '  |  ' + to.name
    }
    return { currentRoutePath, currentRouteInfo, changeRoutePath }

})


export default useRouterStore